<?php
require_once( 'Zend/Db.php' );
require_once( 'Zend/Db/Table.php' );
require_once( 'Zend/Db/Table/Abstract.php' );

class PACIENTE extends Zend_Db_Table_Abstract
{
        protected $_name = 'PACIENTE';      
        
        public function listPacientes(){
        	$where = "PNOMBRE_PACIENTE like '" . $this->nombre."%' AND APELLIDO_PACIENTE like '" . $this->apellido."%' AND PDNI like '" . $this->dni."%' AND POBRA_SOCIAL like '" . $this->osocial."%' AND PACTIVE = true";
            $result = $this->fetchAll($where ,null,10,0);
            return $result;
        }
        
		public function showPaciente(){
        	$where = $this->param . " like '" . $this->data."%'";
            $result = $this->fetchAll($where ,null,10,0);
            return $result;
        }
		        
		public function listallPacientes(){
        	$where = "PACTIVE = TRUE";
            $result = $this->fetchAll($where ,null,0,0);
            return $result;
        }
        
		public function delPacientes(){
        	$where = "PDNI =".$this->dni;
        	
        	$data = array('PACTIVE' => false);
        	$result = $this->update($data, $where);
            return $result;
        	
        }

		public function insPacientes(){
        	$data = array('PDNI' => $this->dni,
									  'PNOMBRE_PACIENTE' => $this->nombre,   
									  'APELLIDO_PACIENTE' => $this->apellido,   
									  'PFECHA_DE_NAC' => $this->date,   
									  'PSEXO' => $this->sexo,
        							  'PDOMICILIO' => $this->direccion,   
									  'POBRA_SOCIAL' => $this->osocial,   
									  'PNRO_AFILIADO' => $this->nroafiliado,   
									  'PPLAN' => $this->plan,
        							  'PFECHA_PRIMER_CONSULTA' => $this->fechaprimer,   
									  'PPESO' => $this->peso,
        							  'PACTIVE' => true);
        	
            try{ 	
            $result = $this->insert($data);
            }catch(Exception $e){
            	return FALSE;
            }
            return $result;
            }
            
		public function updatePacientes(){
        	$data = array('PDNI' => $this->dni,
									  'PNOMBRE_PACIENTE' => $this->nombre,   
									  'APELLIDO_PACIENTE' => $this->apellido,   
									  'PFECHA_DE_NAC' => $this->date,   
									  'PSEXO' => $this->sexo,
        							  'PDOMICILIO' => $this->direccion,   
									  'POBRA_SOCIAL' => $this->osocial,   
									  'PNRO_AFILIADO' => $this->nroafiliado,   
									  'PPLAN' => $this->plan,
        							  'PFECHA_PRIMER_CONSULTA' => $this->fechaprimer,   
									  'PPESO' => $this->peso);
        	$where = 'PDNI='.$this->auxdni;
        	
             	
            $result = $this->update($data, $where);
            return $result;
		}
		
		public function pacexists() {
        	$select = $this->select();
        	$select->from($this->_name,'COUNT(*) AS num' );
        
       		$where = $this->_where($select, "PDNI = '" . $this->dni . "' AND PACTIVE = true");
        	$result = $this->fetchRow($where)->num;

        	return $result;
    }
}
